package com.guinea.generator;

import com.guinea.core.utils.StringUtils;

public class MappingFormElement {
	String title;

	String defaultValue;

	String required;

	String minlength;

	String maxlength;

	String unique;

	String dateFormat;

	String email;

	String anyphone;

	String zip;

	String url;

	String precision;

	String scale;

	String range;

	String rangelow;

	String rangehigh;

	MappingProperty parent;

	public MappingFormElement(String title, String defaultValue,
			String required, String minlength, String maxlength, String unique,
			String dateFormat, String email, String anyphone, String zip,
			String url, String precision, String range) {
		super();
		this.title = title;
		this.defaultValue = defaultValue;
		this.required = StringUtils.defaultString(required, "false");
		this.minlength = minlength;
		this.maxlength = maxlength;
		this.unique = StringUtils.defaultString(unique, "false");
		this.dateFormat = dateFormat;
		this.email = StringUtils.defaultString(email, "false");
		this.anyphone = StringUtils.defaultString(anyphone, "false");
		this.zip = StringUtils.defaultString(zip, "false");
//		this.url = StringUtils.defaultString(url, "false");
		if (StringUtils.isEmpty(precision)) {
			this.precision = null;
			this.scale = null;
		} else {
			String[] ps = precision.split(",");
			if (ps.length < 1) {
				this.precision = null;
				this.scale = null;
			} else if (ps.length == 1) {
				this.precision = ps[0].trim();
				this.scale = "0";
			} else if (ps.length > 1) {
				this.precision = ps[0].trim();
				this.scale = ps[1].trim();
			}
		}
		this.range = range;
		if (!StringUtils.isEmpty(range)) {
			String[] rs = range.split(":");
			if (rs.length < 1) {
				this.range = null;
			} else if (rs.length == 1) {
				this.rangelow = rs[0].trim();
				this.rangehigh = rs[0].trim();
			} else {
				this.rangelow = rs[0].trim();
				this.rangehigh = rs[1].trim();
			}
		}
	}

	public String getDepends() {
		String d = "";
		if (this.required.equals("true"))
			d += "required,";
		if (this.minlength != null)
			d += "minlength,";
		if (this.maxlength != null)
			d += "maxlength,";
		if (this.email.equals("true"))
			d += "email,";
		if (this.anyphone.equals("true"))
			d += "anyphone,";
		if (this.zip.equals("true"))
			d += "zip,";
//		if (this.url.equals("true"))
//			d += "url,";
		if (this.dateFormat != null)
			d += "date,";
		if (this.precision != null)
			d += "precision,";
		if (this.range != null)
			d += "doubleRange,";
		if (d.length() > 0)
			d = d.substring(0, d.length() - 1);
		return d;
	}

	public String getAnyphone() {
		return anyphone;
	}

	public void setAnyphone(String anyphone) {
		this.anyphone = anyphone;
	}

	public String getDateFormat() {
		return dateFormat;
	}

	public void setDateFormat(String dateFormat) {
		this.dateFormat = dateFormat;
	}

	public String getDefaultValue() {
		return defaultValue;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMaxlength() {
		return maxlength;
	}

	public void setMaxlength(String maxlength) {
		this.maxlength = maxlength;
	}

	public String getMinlength() {
		return minlength;
	}

	public void setMinlength(String minlength) {
		this.minlength = minlength;
	}

	public String getPrecision() {
		return precision;
	}

	public void setPrecision(String precision) {
		this.precision = precision;
	}

	public String getRequired() {
		return required;
	}

	public void setRequired(String required) {
		this.required = required;
	}

	public String getScale() {
		return scale;
	}

	public void setScale(String scale) {
		this.scale = scale;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getUnique() {
		return unique;
	}

	public void setUnique(String unique) {
		this.unique = unique;
	}

	public MappingProperty getParent() {
		return parent;
	}

	public void setParent(MappingProperty parent) {
		this.parent = parent;
	}

	public String getRange() {
		return range;
	}

	public void setRange(String range) {
		this.range = range;
	}

	public String getRangehigh() {
		return rangehigh;
	}

	public void setRangehigh(String rangehigh) {
		this.rangehigh = rangehigh;
	}

	public String getRangelow() {
		return rangelow;
	}

	public void setRangelow(String rangelow) {
		this.rangelow = rangelow;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		this.zip = zip;
	}

}
